package com.iweb.day04;

/**
 * @author WuYongheng
 * @date 2021/10/25
 * @description 分别使用冒泡排序、选择排序，对数组元素进行降序排列，数组元素为50，12 ，45，60，78，90
 */
public class Exam1 {
    public static void main(String[] args) {
        System.out.println("冒泡排序：");
        int [] array = {50,12,45,60,78,90};
        int t=0;
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j]<array[j+1]){
                   t = array[j];
                   array[j]=array[j+1];
                   array[j+1]=t;
                }
            }
        }
        for (int k = 0; k < array.length; k++) {
            System.out.print(array[k]+" ");
        }
        System.out.println();

        System.out.println("选择排序:");
        for (int i = 0; i < array.length; i++) {
            int min = i;
            for (int j = i+1; j < array.length; j++) {
                if(array[i]<array[j]){
                    min=j;
                }
                if(min!=i){
                    t=array[i];
                    array[i]=array[j];
                    array[j]=t;
                }
            }
        }
        for (int j = 0; j < array.length; j++) {
            System.out.print(array[j]+" ");
        }
    }
}
